<!DOCTYPE html>

<html lang="zh-Hans">
  <head>
    <meta charset="utf-8" />
    <meta name="author" content="rogepi" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="/vue.global.js"></script>
    <title>6-custom-input-computed</title>
  </head>

  <body>
    <div id="custom-input-computed-demo">
      <custon-input v-model="searchText"></custon-input>
      <p>{{searchText}}</p>
    </div>
    <script>
      const app = Vue.createApp({
        data() {
          return {
            searchText: 'Hello World',
          };
        },
      });

      app.component('custon-input', {
        props: ['modelValue'],
        emits: ['update:modelValue'],
        template: `
      <input v-model="value">
      `,
        computed: {
          value: {
            get() {
              return this.modelValue;
            },
            set(value) {
              this.$emit('update:modelValue', value);
            },
          },
        },
      });

      app.mount('#custom-input-computed-demo');
    </script>
  </body>
</html>
